package util;

import com.medpro.testengine.core.CommandsList;

public class Validation {

    private CommandsList command;

    public Validation(CommandsList commander) {

        command = commander;
    }

    public CommandsList validationInput(String xpath, String messageXpath) {

        String[] string = {"", "    ", " "};

        for (String s : string) {
            command.clearTypeSubmit(xpath, s)
                    .verifyElementPresent(messageXpath);
        }
        command.clear(xpath)
                .type(xpath, "***)sgjl**")
                .submit(xpath)
                .verifyElementNotPresent(messageXpath);
        return command;
    }

    public CommandsList validationPolicy(String xpathPolicyNumber) {

        String[] policies = {"123.123.123", "fgdgf", "1", "PP9877", "aaaaaaa1234"};
        for (String policy : policies) {
            command.clearTypeSubmit(xpathPolicyNumber, policy)
                    .verifyElementPresent("msg.NotRecog");
        }

        String[] policies1 = {"Q23423", "b12332", "R12312", "123456", "shjd23423"};
        for (String policy : policies1) {
            command
                    .clearTypeSubmit(xpathPolicyNumber, policy)
                    .verifyElementPresent("msg.InvalidPN");
        }

        String[] policies2 = {"A12312", "654321"};
        for (String policy : policies2) {
            command
                    .clearTypeSubmit(xpathPolicyNumber, policy)
                    .verifyElementPresent("msg.NoAccess");
        }

        return command;
    }

    public CommandsList validationEmail(String xpath) {

        command.clearTypeSubmit(xpath, "")
                .verifyElementPresent("rf.InputMsg")
                .verifyTextPresent("Please enter your email address.")
        ;

        String[] emails = {"fdhs", "1111", "asgfsg@dgxsg", "1111@dgs", "ffff@com.1"};
        for (String email : emails) {
            command.clearTypeSubmit(xpath, email)
                    .verifyElementPresent("rf.InputMsg")
                    .verifyTextPresent("Invalid email format")
            ;
        }
        return command;
    }

}
